package com.living.filedownloader.ui.adapter;

import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.living.R;
import com.living.filedownloader.bean.TasksManagerModel;

import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/***
 * 下载适配器
 */
public class TaskItemDownloadedSelectAdapter extends BaseQuickAdapter<TasksManagerModel, BaseViewHolder> {

    private Map<String, TasksManagerModel> mapSel = new ConcurrentHashMap<>();

    public TaskItemDownloadedSelectAdapter(Map<String, TasksManagerModel> mapSel) {
        super(R.layout.item_downloaded_task);
        this.mapSel = mapSel;
    }

    @NotNull
    @Override
    protected BaseViewHolder onCreateDefViewHolder(@NotNull ViewGroup parent, int viewType) {
        BaseViewHolder holder = super.onCreateDefViewHolder(parent, viewType);
        return holder;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, TasksManagerModel model) {
        holder.setGone(R.id.task_action_more, true);
        holder.setGone(R.id.task_action_select, false);
        holder.setText(R.id.task_name_tv, model.getAudioId() + "  " + model.getName());
        holder.setText(R.id.task_status_tv, model.getAuthor()+"");
        if (mapSel.containsKey(model.getAudioId())) {
            holder.setImageResource(R.id.task_action_select, R.drawable.icon_download_selected);
        } else {
            holder.setImageResource(R.id.task_action_select, R.drawable.icon_download_select);
        }
    }


}
